package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.SetMainPushPremisesReqDto;
import com.yixun.qfbao.apidto.SetMainPushPremisesResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TException;
import com.yixun.qfbao.vo.SetMainPushPremisesReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetMainPushPremisesHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(SetMainPushPremisesHander.class);

    @Autowired
    private PremisesApiService premisesApiService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        SetMainPushPremisesReqVo req = (SetMainPushPremisesReqVo)reqDto;
        SetMainPushPremisesReqDto setMainPushPremisesReqDto = req.getParams();
        BaseResponseDTO<SetMainPushPremisesResDto> res = new BaseResponseDTO<SetMainPushPremisesResDto>();
        SetMainPushPremisesResDto resDto = new SetMainPushPremisesResDto();
        try {
            resDto = premisesApiService.setMainPushPremises(setMainPushPremisesReqDto);
        }catch (TException t) {
            logger.error("SetMainPushPremisesHander error: {}", t);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(t.getErrorMsg());
        } catch(Exception e) {
            logger.error("SetMainPushPremisesHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("设置主推楼盘失败");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
